<%@page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<%@page import="java.util.*,com.mysql.jdbc.Driver,java.sql.*"%>
<%
request.setCharacterEncoding("UTF-8");
String un=request.getParameter("uname");//用户Email
String newpass=request.getParameter("newpass");//生成的用户的新密码

System.out.println(un);
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPasswd="";
String dbName="a0713225307";

try{
	Class.forName(driverName).newInstance();
	String u="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=UTF-8";
	java.sql.Connection con=java.sql.DriverManager.getConnection(u,userName,userPasswd);
    String sql="update users set uPassword='"+newpass+"' where uName='"+un+"'";
	Statement statement=con.createStatement();
	
	if(statement.executeUpdate(sql)==1){
		System.out.println("success");
		response.sendRedirect("forget.jsp?flag=1");
	}else{
		System.out.println("fail");
		response.sendRedirect("forget.jsp?flag=2");
	}
	
	if(statement!=null){
		statement.close();
	}
	if(con!=null){
		con.close();
	}
	}catch(Exception e){
		e.printStackTrace();
	}
%>